<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:nwisdocs="http://wales.nhs.uk/nwis/docs"
	exclude-result-prefixes="xs xsi">

  <xsl:template name="admission" match="nwisdocs:DocumentBody/nwisdocs:HospitalAdmission">
    <div class="boxed-section" id="{local-name()}">
      <h2>Admission details</h2>


      <xsl:choose>
        <xsl:when test="(nwisdocs:EffectiveTime/nwisdocs:Start/nwisdocs:Date[text() != '']) or 
                  (nwisdocs:EffectiveTime/nwisdocs:Start/nwisdocs:Time[text() != '']) or
                  (nwisdocs:MethodOfAdmission/nwisdocs:ClinicalInformation/nwisdocs:ClinicalCodeDescription[text() != '']) or
                  (nwisdocs:SourceOfAdmission/nwisdocs:ClinicalInformation/nwisdocs:ClinicalCodeDescription[text() != '']) or
                  (nwisdocs:Location/nwisdocs:UnstructuredAddress[text() != ''])">

          <xsl:choose>
            <xsl:when test="nwisdocs:EffectiveTime/nwisdocs:Start/nwisdocs:Date[text() != '']">
              <label>Date of admission</label>
              <span>
                <xsl:call-template name="standard_date">
                  <xsl:with-param name="date" select="nwisdocs:EffectiveTime/nwisdocs:Start/nwisdocs:Date"/>
                </xsl:call-template>
              </span>
              <br />
            </xsl:when>
          </xsl:choose>


          <xsl:choose>
            <xsl:when test="nwisdocs:EffectiveTime/nwisdocs:Start/nwisdocs:Time[text() != '']">
              <label>Time of admission</label>
              <span>
                <xsl:call-template name="standard_time">
                  <xsl:with-param name="time" select="nwisdocs:EffectiveTime/nwisdocs:Start/nwisdocs:Time"/>
                </xsl:call-template>
              </span>
              <br/>
            </xsl:when>
          </xsl:choose>
          <xsl:choose>
            <xsl:when test="nwisdocs:MethodOfAdmission/nwisdocs:ClinicalInformation/nwisdocs:ClinicalCodeDescription[text() != '']">
              <label>Method of admission</label>
              <span>
                <xsl:value-of select="nwisdocs:MethodOfAdmission/nwisdocs:ClinicalInformation/nwisdocs:ClinicalCodeDescription"/>
              </span>
              <br/>
            </xsl:when>
          </xsl:choose>

          <xsl:choose>
            <xsl:when test="nwisdocs:SourceOfAdmission/nwisdocs:ClinicalInformation/nwisdocs:ClinicalCodeDescription[text() != '']">
              <label>Source of admission</label>
              <span>
                <xsl:value-of select="nwisdocs:SourceOfAdmission/nwisdocs:ClinicalInformation/nwisdocs:ClinicalCodeDescription"/>
              </span>
              <br/>

            </xsl:when>
          </xsl:choose>

          <xsl:choose>
            <xsl:when test="nwisdocs:Location/nwisdocs:UnstructuredAddress[text() != '']">
              <label>Hospital site</label>
              <span>
                <xsl:value-of select="nwisdocs:Location/nwisdocs:UnstructuredAddress"/>
              </span>
            </xsl:when>

          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <label>None recorded</label>
        </xsl:otherwise>
      </xsl:choose>
    </div>
  </xsl:template>

</xsl:stylesheet>
